<template>
<div class="repairTask">
    <header-btn style="margin-bottom:10px"  :btnList='tabArr' :tabIndex='curTabIndex' @changetabIndex='getCurTabIndexFn'/>
        <!-- 当前任务 -->
    <div class="tableBody" >
        <lpj-table-vue :baseNum='pageTotal.per_page*(pageTotal.current_page-1)' ref="lpjTable" :tableData="tableData" :tableHeaderData="tableHeaderData[curTabIndex]" @linkBtnFn="linkBtnFn" ></lpj-table-vue>
        <pagination v-if="pageTotal.total&&pageTotal.total>10"  align="right" :paginationMes="pageTotal" @sizeChangeFn="handleSizeChange" @currentChangeFn="handleCurrentChange"></pagination>
    </div>
     <dialog-vue dialogTitle="新增维修记录" :dialogVisible="dialogVisible" @dialogVisibleChangeFn="dialogVisibleChangeFn" :ruleForm="ruleForm"  @goCancel="goCancel"  @goSubmit="goSubmit">
    </dialog-vue>
</div>
</template>
<script>
/* eslint-disable */
/********获取维修任务       确认         填写           报修信息 */
import {getRepairTasksList,taskConfirm,editTaskRepair,repairInfo} from './api'
import headerBtn from "@/components/headerBtn"/**表头tab */
import LpjTableVue from "@/components/LpjTableVue"
import Pagination from "@/components/Pagination"
import DialogVue from "@/components/DialogVue"
import constObj from '@/config/const' /**表头常数 */
export default {
  name: "repairTask",
  components: { headerBtn,LpjTableVue,DialogVue,Pagination },
  data() {
    var validateNum = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('金额不能为空'));
        }
        if (!/^(-?\d+)(\.\d{1,2})?$/.test(value)){
            callback(new Error('请输入最多两位小数的数字值'));
        } else {
            callback();
        }
      };
    return {
        tabArr:[
           {num:'',content:'维修任务'},
		   {num:'',content:'维修报表'},
		],
        curTabIndex:0,
        pageTotal:{per_page:10,current_page:1,totol:0},
        /**分页数据参数 */
        pageTotal2:{per_page:10,current_page:1,totol:0},
        // activeName: 'now',/**选中的el-tabs */
        tableData: [],/**当前任务-表格数据 */
        tableHeaderData:constObj.tableHeaderOfRepairManager,
        dialogVisible: false,/*是否显示领用弹框*/
        ruleForm: {
          formList: [],
          addForm:[]
       },/*领用表单*/
    }
  },
  created() {
    this.curTabIndex=Number(localStorage.curTabIndex) ||0
    this.getCurTabIndexFn(this.curTabIndex)
  },
  methods: {
      /*tab切换 */
      getCurTabIndexFn(tabindex){
          localStorage.curTabIndex = tabindex
          this.curTabIndex=tabindex
          if(tabindex==0){
            let query = {page:this.pageTotal.current_page,num:this.pageTotal.per_page}
            getRepairTasksList(query).then(res=>{
                this.pageTotal={per_page:Number(res.per_page),total: res.total,current_page:Number(res.current_page)}
                this.tableData = res.data
            })
          }
      },
        /**控制是否显示弹窗 */
        dialogVisibleChangeFn(val){
            this.dialogVisible = val
            if(!val){
                this.ruleForm.formList=[]
            }
        },
        // /*监听资产领用弹窗点击确定*/
        goSubmit(e){
            editTaskRepair(e).then((res)=>{
                this.getCurTabIndexFn(this.curTabIndex)
                this.goCancel()
                this.$store.commit('changeDisabled', false)
                this.getTable();
            }).catch(err=>{
                this.$store.commit('changeDisabled', false)
            })
        },
        /**弹窗取消按钮 */
        goCancel(){
        this.dialogVisible = false
        this.ruleForm = {formList:[],addForm:[]}
        },
      /**监听操作 */
      linkBtnFn(sym,row){
          switch(sym){
              case '待确认':/* 确认 */
                 taskConfirm({id:row.id}).then(res=>{this.getCurTabIndexFn(this.curTabIndex)}) ;break;
              case '填写维修记录': /*编辑*/
                 this.toLinkReturnFn(row);break; 
              case '详情': /*详情*/
                 this.$router.push({name:"requireRepairDetail",query:{key:row.id, param: this.$route.meta.title}})
                 ;break; 
          }
      },
       /*编辑*/
     toLinkReturnFn(val){
         repairInfo({id:val.id}).then(res=>{
             log(res)
             let arr = res.guarantee&&res.guarantee.length?res.guarantee.map(item=>{return item.ri_url}):[]
             this.ruleForm.formList = [
                  { type: 'number', name:'rp_price', label: '维修花费', placeholder: '请输入维修花费', className: 'two', formValue:res.rp_price?Number(res.rp_price):'',rules:[{ required: true, message: '请输入维修花费', trigger: 'blur' },{ type:'number', message: '请输入数字', trigger: 'blur' }]},
                  { type: 'textarea', name:'rp_remark', label: '维修描述', placeholder: '请输入维修描述', className: 'two', formValue: res.rp_remark,rules:[{ required: true, message: '请输入维修描述', trigger: 'blur' }]},
                  { type: 'upload',name:'rp_ri_url', label: '图片', limitNum: 6,formValue:arr,rules:[{ required: true, message: '请上传报修图片', trigger: 'change',type: 'array', }]}
                ]
                this.ruleForm.addForm = [
                  {name:'id',formValue:val.id},
                  {name:'type',formValue:val.rp_status-1}
                ]
                this.dialogVisible = true
         })
    },
     //分页改变总条数
      handleSizeChange(val) {
            this.pageTotal.current_page = 1
            this.pageTotal.pageSize = val
            this.getCurTabIndexFn(this.curTabIndex)
      },
     //分页改变当前
      handleCurrentChange(val) {
            this.pageTotal.current_page=val
            this.getCurTabIndexFn(this.curTabIndex)
      }
  }
};
</script>
<style lang="stylus" scoped>
.repairTask 
    font-size 14px
    .tableBody
        padding 38px 40px
        background-color #fff
</style>